import requests
import json
import pandas as pd
# 获取网页上的数据
def f1():
    url='https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=chinaDayList,chinaDayAddList,nowConfirmStatis,provinceCompare'
    r = requests.get(url)
    res = json.loads(r.text)
    return res
def f2():
    res = f1()
#输出列表的标题
    df = pd.DataFrame(columns=['时 间','确诊人数','治愈人数','死亡人数'])
#获取所对应的数据
    for i in range(len(res['data']['chinaDayList'])):
         df.loc[i+1]=[res['data']['chinaDayList'][i]['y']+'.'+res['data']['chinaDayList'][i]['date'],
         res['data']['chinaDayList'][i]['confirm'],
         res['data']['chinaDayList'][i]['heal'],
         res['data']['chinaDayList'][i]['dead']]
    df.to_csv('D:\\python项目\\大作业\\大作业.csv', index=0, encoding='utf_8_sig')
    return(print('end'))
#调用函数
f1()
f2()





